import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.io.entity.EntityUtils;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;


public class HttpClientDemo {
    public static void main(String[] args) throws IOException, ParseException {
        CloseableHttpClient aDefault = HttpClients.createDefault();

        HttpGet httpGet = new HttpGet("http://127.0.0.1:8808/");
        CloseableHttpResponse response = aDefault.execute(httpGet);
        // 打印下响应码
        System.out.println(response.getCode());
        // 获取下相应头信息
        Header[] headers = response.getHeaders();
        for (Header header : headers) {
            System.out.println(header.getName());
            System.out.println(header.getValue());
        }

        HttpEntity entity = response.getEntity();
        String result = EntityUtils.toString(entity);
        System.out.println(result);


    }
}
